<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>34. 使用mathcAll完成全局匹配</title>
    </head>
    <body>
        <h1>houdunren.com</h1>
        <h2>hdcms.com</h2>
            <h1>后盾人</h1>
    </body>
    <script>
        // let reg=/<(h[1-6])>([\s\S]+?)<\/\1>/ig
        // const body=document.body;
        // console.log(body.innerHTML.match(reg)) //["<h1>houdunren.com</h1>", "<h2>hdcms.com</h2>", "<h1>后盾人</h1>"]


        let reg = /<(h[1-6])>([\s\S]+?)<\/\1>/gi
        const body = document.body;
        //matchAll hbuilderx中会报错，谷歌浏览器中不会
        const hd = body.innerHTML.matchAll(reg);
        let contents = [];
        for (const iterator of hd) {
            console.log(iterator) //打印了多个array
            contents.push(iterator[2])
        }
        console.table(contents)
    </script>
</html>
